<template>
  <view class="factory-detail-card">
    <view class="factory-detail-title">{{ info.articleName }}</view>
    <view class="factory-detail-admin-card">
      <view class="admin-row">
        <image
          class="admin-icon"
          src="/static/icon/admin_icon.png"
        />
        <text class="admin-label">负责人：</text>
        <text class="admin-value"
          >{{ info.personChargeName }} {{ info.personChargePhone }}</text
        >
      </view>
      <view class="admin-row">
        <image
          class="admin-icon"
          src="/static/icon/map_icon.png"
        />
        <text class="admin-value">{{ info.contactAddress }}</text>
      </view>
    </view>
    <view class="factory-detail-desc">
      <rich-text :nodes="processedContent"></rich-text>
    </view>
    <view class="factory-footer-bar">
      <van-button
        class="footer-btn"
        type="primary"
        color="#0C8D6A"
        block
        round
        @click="openMap"
        >导航</van-button
      >
      <van-button
        class="footer-btn"
        type="primary"
        color="#0C8D6A"
        block
        round
        @click="callPhone"
        >联系负责人</van-button
      >
    </view>
  </view>
</template>

<script>
  import { openNavigation } from '../../../common/utils.js'
  import RichTextUtils from '../../../common/richTextUtils.js'
  export default {
    name: 'FactoryDetailCard',
    props: {
      info: {
        type: Object,
        required: true
      }
    },
    computed: {
      processedContent() {
        return RichTextUtils.limitImageWidth(this.info.articleContent)
      }
    },
    methods: {
      openMap() {
        if (!this.info.contactAddress) {
          uni.showToast({ title: '无地址信息', icon: 'none' })
          return
        }
        openNavigation({
          latitude: this.info.latitude,
          longitude: this.info.longitude,
          name: this.info.contactAddress
        })
      },
      callPhone() {
        if (!this.info.personChargePhone) {
          uni.showToast({ title: '无联系电话', icon: 'none' })
          return
        }
        uni.makePhoneCall({ phoneNumber: this.info.personChargePhone })
      }
    }
  }
</script>

<style scoped lang="scss">
  .factory-detail-card {
    width: 100vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fff;
  }
  .factory-detail-title {
    margin: 40rpx 0;
    font-size: 36rpx;
    font-weight: 600;
    color: #333;
    text-align: center;
  }
  .factory-detail-admin-card {
    width: 686rpx;
    background: rgba(144, 165, 159, 0.1);
    border-radius: 15rpx;
    margin: 0 32rpx;
    padding: 32rpx 20rpx;
    display: flex;
    flex-direction: column;
    gap: 24rpx;
    box-sizing: border-box;
  }
  .admin-row {
    display: flex;
    align-items: center;
  }
  .admin-icon {
    width: 32rpx;
    height: 32rpx;
    margin-right: 8rpx;
  }
  .admin-label {
    font-size: 24rpx;
    color: #666666;
    margin-right: 4rpx;
  }
  .admin-value {
    font-size: 24rpx;
    color: #666666;
    word-break: break-all;
  }
  .factory-detail-desc {
    width: calc(100vw - 64rpx);
    margin-top: 47rpx;
    font-size: 28rpx;
    color: #666;
    text-align: left;
    line-height: 1.8;
  }
  .factory-footer-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    padding: 24rpx 32rpx 32rpx 32rpx;
    box-shadow: 0rpx 7rpx 46rpx 0rpx rgba(0, 0, 0, 0.33);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .footer-btn {
    flex: 1;
    height: 88rpx;
    font-size: 32rpx;
    border-radius: 44rpx;
    margin: 0 12rpx;
    font-weight: 500;
    color: #fff;
    background: #0c8d6a;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
  }
</style>
